package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.Organ;
import org.springframework.util.ObjectUtils;

import javax.persistence.*;
import java.util.Date;

/**
 * 商品库存
 *
 * @author 文卡<wkwenka@gmail.com>  on 17-3-24.
 */
@Entity
@Table(name = "goods_store")
public class GoodsStock extends BaseEntity {

    @ManyToOne
    private Goods goods;

    @Column(name = "store_num")
    private Double storeNum; //库存数量

    @Column(name = "in_transit")
    private Double inTransit;//在途数量

    @Column(name = "freeze_up")
    private Double freezeUp ;//冻结数量

    private Integer state; // -1:在途 0:冻结 1:启用

    @ManyToOne
    private Organ store;

    @Transient
    private String goodsName;

    @Transient
    private String goodsId;

    @JSONField(format = "yyyy-MM-dd hh:mm:ss")
    @Column(name = "update_time", nullable = false)
    private Date updateTime = new Date();

    @Transient
    private String storeName;  //仓库名称

    @Transient
    private String storeId;     //仓库ID

    public Organ getStore() {
        return store;
    }

    public void setStore(Organ store) {
        this.store = store;
    }

    public String getStoreId() {
        if(!ObjectUtils.isEmpty(store)){
            this.storeId  = store.getId();
        }
        return storeId;
    }

    public void setStoreId(String storeId) {
        this.storeId = storeId;
    }

    public String getStoreName() {
        if(!ObjectUtils.isEmpty(store)){
            this.storeName  = store.getName();
        }

        return storeName;
    }

    public void setStoreName(String storeName) {
        this.storeName = storeName;
    }

    public Double getInTransit() {
        return inTransit;
    }

    public void setInTransit(Double inTransit) {
        this.inTransit = inTransit;
    }

    public Double getFreezeUp() {
        return freezeUp;
    }

    public void setFreezeUp(Double freezeUp) {
        this.freezeUp = freezeUp;
    }

    public Goods getGoods() {
        return goods;
    }

    public void setGoods(Goods goods) {
        this.goods = goods;
    }

    public Double getStoreNum() {
        return storeNum;
    }

    public void setStoreNum(Double storeNum) {
        this.storeNum = storeNum;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public String getGoodsName() {
        return goods != null ? goods.getName() : goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public String getGoodsId() {
        return goods != null ? goods.getId() : goodsId;
    }

    public void setGoodsId(String goodsId) {
        this.goodsId = goodsId;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
